<?php
	/**
	 * 提现
	 * @param unknown_type $pMerBillNo
	 * @return string
	 */
	function DoDwTrade($user_id,$platformNo,$pTrdAmt,$post_url){
		$pWebUrl= SITE_DOMAIN.APP_ROOT."/index.php?m=Home&c=collocation&a=response_go&class_name=".getCollName()."&class_act=DoDwTrade&from=".strim($_REQUEST['from']);//web方式返回

		$pS2SUrl= SITE_DOMAIN.APP_ROOT."/index.php?m=Home&c=collocation&a=notify&class_name=".getCollName()."&class_act=DoDwTrade&from=".strim($_REQUEST['from']);//s2s方式返回

		$user = array();
		$user = get_user_info("*","id = ".$user_id);

		$fuioupay_log = array();
		$fuioupay_log['code'] = 'toWithdraw';
		$fuioupay_log['create_date'] = to_date(TIME_UTC,'Y-m-d H:i:s');
		$GLOBALS['db']->autoExecute(DB_PREFIX."fuioupay_log",$fuioupay_log);
		$requestNo = $GLOBALS['db']->insert_id();
		$fee = 0 ;//getCarryFee($pTrdAmt,$user);

		$result = GetIpsUserMoney($user_id,0);
		$pBalance = $result['pBalance'];
		if(floatval($pTrdAmt) + floatval($fee) > floatval($pBalance))
		{
			//showIpsInfo("余额不足",SITE_DOMAIN.url("index","index"));
            echo '<html><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=2.0, user-scalable=0,minimum-scale=0.5"><meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge"><meta http-equiv="content-type" content="text/html; charset=UTF-8" /></head><body><form name="form1" id="form1" method="post" action="?index.php?c=uccenter&a=index" target="_self">		
		<input type="hidden" value="提交"></input>
 		<div style="width:100%;text-align:center;padding:10px 0;text-align: 18px;"><div style="font-size:20px;color:red;padding:20px 0;">余额不足</div>页面正在跳转，请稍后...</div>
		<div style="width:100%;text-align:center;padding:10px 0;text-align: 18px;"><button type="button" onclick="do_submit()" style="height:50px;padding:10px 20px;text-align: 30px;font-size: 18px;">手动退出</button></div>
		</form>
		</body></html>
		<script language="javascript">
		//document.form1.submit();
		function do_submit(){
		    document.form1.submit();
		}
		</script>\';</body>';
			return ;
		}
		
		$data = $Sign_data= array();
		$data['requestNo'] = $requestNo;
		$data['create_time'] = TIME_UTC;
		$data['feeMode'] = 'USER';//
		$data['fee'] = $fee;
		$data['user_id'] = $user_id; 
		
		$Sign_data['mchnt_cd'] = $platformNo;
		$data['mchnt_txn_ssn'] = $Sign_data['mchnt_txn_ssn'] = $user['id'].time();
		$data['login_id'] = $Sign_data['login_id'] = $user['mobile'];//用户登录名 普通用户 手机号
		//$data['amt'] = $pTrdAmt - $fee;
		$data['amt'] = $pTrdAmt;
		$Sign_data['amt'] = $pTrdAmt*100;
		$Sign_data['back_notify_url'] = $pS2SUrl;//商户后台通知地址
		$Sign_data['page_notify_url'] = $pWebUrl;//商户返回地址
		
		$GLOBALS['db']->autoExecute(DB_PREFIX."fuioupay_withdraw",$data,'INSERT');
		$id = $GLOBALS['db']->insert_id();

		ksort($Sign_data);
		foreach($Sign_data as $k => $v){
			if($k == 'page_notify_url'){
				$Sign_old .=$v;
			}else{
				$Sign_old .= $v."|";
			}
		}
		
		$pSign=rsaSign($Sign_old,PRIVATE_KEY_PATH);
		
		if($sys=='pc'){
			$act = 'bha';
		}elseif($sys=='mobile'){
			$act = 'bhawireless';
		}
		$strhtml = '';
		foreach($Sign_data as $k => $v){
			$strhtml .= '<input type="hidden" name="'.$k.'" value="'.$v.'" /><br/>';
		}
			
		$html = '<html><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=2.0, user-scalable=0,minimum-scale=0.5"><meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge"><meta http-equiv="content-type" content="text/html; charset=UTF-8" /></head><body>
		<form name="form1" id="form1" method="post" action="'.$post_url.'" target="_self">		
		<input type="hidden" name="signature" value="'.$pSign.'" />		
		'.$strhtml.'
 		<input type="hidden" value="提交"></input>
 		<div style="width:100%;text-align:center;padding:10px 0;text-align: 18px;"><img src="/public/images/loading.gif" />页面正在跳转，请稍后...</div>
		<div style="width:100%;text-align:center;padding:10px 0;text-align: 18px;"><button type="button" onclick="do_submit()" style="height:50px;padding:10px 20px;text-align: 30px;font-size: 18px;">手动提交</button></div>
		</form>
		</body></html>
		<script language="javascript">
		//document.form1.submit();
		function do_submit(){
		    document.form1.submit();
		}
		</script>\';';
		
		$fuioupay_log = array();
		$fuioupay_log['html'] = $html;
		$GLOBALS['db']->autoExecute(DB_PREFIX."fuioupay_log",$fuioupay_log,'UPDATE','id='.$requestNo);
		return $html;
	
	
	}
	
	
	function DoDwTradeCallBack($str3Req,$platformNo,$post_url,$mchnt_user){
		$mchnt_txn_ssn = $str3Req["mchnt_txn_ssn"];
		if($mchnt_txn_ssn){
			unset($str3Req["mchnt_txn_ssn"]);
		}

		if ($str3Req['code'] == '0000'){
			$where = " mchnt_txn_ssn = '".$mchnt_txn_ssn."'";
			
			require_once APP_ROOT_PATH."system/libs/user.php";
			
			
			$sql = "update ".DB_PREFIX."fuioupay_withdraw set is_callback = 1 where is_callback = 0 and ".$where;
			
			$GLOBALS['db']->query($sql);
			if ($GLOBALS['db']->affected_rows()){
				
				$info = $GLOBALS['db']->getRow("select user_id,amt,fee from ".DB_PREFIX."fuioupay_withdraw where ".$where);
				/*
				modify_account(array('money'=>-$info['amt']),$info['user_id'],"托管提现",8,1);
				*/
				//扣手续费
				if($info['fee']!=0){
					require_once APP_ROOT_PATH.'system/collocation/fuioupay/transferBu.php';
					$rs = transferBu($mchnt_user, $info['user_id'], $info['fee'], $platformNo, $post_url,0,0,9,"托管提现手续费");
					
					/*if($rs['resp_code']=="0000"){
						modify_account(array('money'=>-$info['fee']),$info['user_id'],"托管提现手续费",9,1);
						
					}*/
				}
				/*
				$data = array();
				$data['money'] = $info['amt'];
				$data['fee'] = $info['fee'];
				$data['real_name'] = '托管提现';
				$data['bankzone'] = '托管提现';
				$data['bankcard'] = '托管提现';
				$data['user_id'] = intval($info['user_id']);
					
					
				$data['update_time'] = $data['create_time'] = TIME_UTC;
				$data['create_date'] = to_date(TIME_UTC,"Y-m-d");
				$data['status'] = 1;
				
				$GLOBALS['db']->autoExecute(DB_PREFIX."user_carry",$data,"INSERT");
				*/		
				//操作成功
				if (isset($str3Req['message']))
					$str3Req['message'] = '更新is_callback=1成功';
				
			}else{
				if (isset($str3Req['message']))
					$str3Req['message'] = '更新is_callback=1失败';
			}
			$GLOBALS['db']->autoExecute(DB_PREFIX."fuioupay_withdraw",$str3Req,'UPDATE',$where);
			return 1;
		}else{
			return 0;
		}
		
	}	
	
?>